package com.brillilab.service.core.crm.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brillilab.common.constant.ClientTypeEnum;
import com.brillilab.common.constant.KeyProfixConstant;
import com.brillilab.common.constant.TimeConstant;
import com.brillilab.common.redis.RedisCache;
import com.brillilab.common.utils.CodeUtil;
import com.brillilab.common.utils.MyBeanUtils;
import com.brillilab.dao.mapper.crm.CrmUsersMapper;
import com.brillilab.domain.enums.crm.CrmUserEnum;
import com.brillilab.domain.po.crm.CrmUsers;
import com.brillilab.domain.po.user.Users;
import com.brillilab.domain.vo.crm.CrmUsersInfoVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.core.crm.ICrmUsersService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * @author zlb
 * @Title: CrmUsersServiceImpl
 * @ProjectName brill_lab
 * @Description: TODO
 * @date 2019/6/24 16:54
 */
@Service
@Transactional
public class CrmUsersServiceImpl extends ServiceImpl<CrmUsersMapper, CrmUsers> implements ICrmUsersService {

    @Resource
    private CrmUsersMapper crmUsersMapper;

    @Override
    public CrmUsers selectUser(String userName, Integer state) {
        LambdaQueryWrapper<CrmUsers> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CrmUsers::getUserName, userName);
        if (state != null) {
            wrapper.eq(CrmUsers::getUserState, state);
        }
        return crmUsersMapper.selectOne(wrapper);
    }

    @Override
    public CrmUsers selectUser(String userName, String password, Integer state) {
        LambdaQueryWrapper<CrmUsers> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CrmUsers::getUserName, userName);
        wrapper.eq(CrmUsers::getPassword, DigestUtils.md5Hex(password).toUpperCase());
        if (state != null) {
            wrapper.eq(CrmUsers::getUserState, state);
        }
        return crmUsersMapper.selectOne(wrapper);
    }
}
